package name.suray.andrey;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class Prop implements IParser {
	
	public Map<String,String> parse() throws IOException{
		
		System.out.println("In Prop.parse()...");
		Map<String,String> map = new HashMap<String,String>();
		Properties prop = new Properties();		 
    	
		try {
			
    		prop.load(new FileInputStream("D:\\config.properties"));
    		map.put("class", prop.getProperty("class") );
    		map.put("field1", prop.getProperty("field1") );
    		map.put("field2", prop.getProperty("field2") );
    		map.put("field3", prop.getProperty("field3") );
               
    	} catch (IOException ex) {
    		ex.printStackTrace();
        }
	
    	boolean flag = Character.isUpperCase( map.get("class").charAt(0) );
    	if(flag && map.get("class") != null && map.get("field1") != null 
			&& map.get("field2") != null & map.get("field3") != null){
			return map;			
		}else throw new IOException("Invalid config file.");
	}
}
